package com.assessment.repository.impl;

import com.assessment.mapper.AssessmentItemMapper;
import com.assessment.mapper.AssessmentRelationMapper;
import com.assessment.model.entity.AssessmentItem;
import com.assessment.model.entity.AssessmentRelation;
import com.assessment.repository.AssessmentTaskRepository;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 评测任务仓储实现类
 */
@Repository
public class AssessmentTaskRepositoryImpl implements AssessmentTaskRepository {

    @Autowired
    private AssessmentRelationMapper relationMapper;

    @Autowired
    private AssessmentItemMapper itemMapper;

    @Override
    public List<AssessmentRelation> getTeacherTasks(Integer teacherId, Integer periodId) {
        return relationMapper.findTeacherTasks(teacherId, periodId);
    }

    @Override
    public AssessmentRelation getTaskById(Integer relationId) {
        return relationMapper.selectById(relationId);
    }

    @Override
    public List<AssessmentItem> getAssessmentItems(Integer ruleId) {
        return itemMapper.findByRuleId(ruleId);
    }

    @Override
    public boolean updateTaskStatus(Integer relationId, Integer status) {
        UpdateWrapper<AssessmentRelation> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", relationId).set("assess_status", status);
        return relationMapper.update(null, updateWrapper) > 0;
    }
}
